import sys
import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
APP_PATH = os.path.join(BASE_DIR, "app")

sys.path.insert(0, APP_PATH)


class DefaultConfig(object):
    BASE_DIR = BASE_DIR

    # 设置密钥
    SECRET_KEY = "kjgdahdjGKJ1273JGDArda13GD5yRNTcYkx7NtzHpumOK4WqplfxgGld"

    # api设置
    API_PREFIXES = "api"
    API_VERSION = "v1"

    # app设置
    APP_VERSION = "1.0"

    # mysql 配置
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:111@127.0.0.1/epp'  # 连接地址
    SQLALCHEMY_TRACK_MODIFICATIONS = False  # 是否追踪数据变化
    # SQLALCHEMY_ECHO = True  # 查询时会显示原始SQL语句

    # redis 配置
    REDIS_URL = "redis://:@localhost:6379/0"

    # 缓存配置
    CACHE_URL = "redis://:@localhost:6379/1"

    # 频率限制
    RATE_THROTTLE = "3/s"

    #
    SCHEDULER_API_PREFIX = f"/{API_PREFIXES}/{API_VERSION}/scheduler"

    SCHEDULER_API_ENABLED = True

    TOKEN_EXPIRES = 60 * 60 * 24
    TOKEN_REFRESH_EXPIRES = 60 * 60 * 24 * 2

    WHITE_LIST = ['/api/v1/user/login', '/shutdown']

    # 语言设置
    LANGUAGE = "zh_hans"
    # 日志配置
    LOG_NAME = "flask_app"
    LOG_LEVEL = "INFO"  # 日志输出到文件中的最低等级
    LOG_DIR = "logs/flask-app.log"  # 日志存储目录
    MAX_BYTES = 1024 * 1024 * 200  # 日志文件的最大备份数量
    BACKUP_COUNT = 3


class DevelopmentConfig(DefaultConfig):
    DEBUG = True


class ProductionConfig(DefaultConfig):
    DEBUG = False
    SQLALCHEMY_ECHO = False
    BASE_DIR = BASE_DIR

    # 设置密钥
    SECRET_KEY = "kjgdahdjGKJ1273JGDArda13GD5yRNTcYkx7NtzHpumOK4WqplfxgGld"

    # api设置
    API_PREFIXES = "api"
    API_VERSION = "v1"

    # app设置
    APP_VERSION = "1.0"

    # mysql 配置
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:111@127.0.0.1/epp'  # 连接地址
    SQLALCHEMY_TRACK_MODIFICATIONS = False  # 是否追踪数据变化
    # SQLALCHEMY_ECHO = True  # 查询时会显示原始SQL语句

    # redis 配置
    REDIS_URL = "redis://:@localhost:6379/0"

    # 缓存配置
    CACHE_URL = "redis://:@localhost:6379/1"

    # 频率限制
    RATE_THROTTLE = "3/s"

    #
    SCHEDULER_API_PREFIX = f"/{API_PREFIXES}/{API_VERSION}/scheduler"

    SCHEDULER_API_ENABLED = True

    TOKEN_EXPIRES = 60 * 60 * 24
    TOKEN_REFRESH_EXPIRES = 60 * 60 * 24 * 2

    WHITE_LIST = ['/api/v1/user/login', '/shutdown']

    # 语言设置
    LANGUAGE = "zh_hans"
    # 日志配置
    LOG_NAME = "flask_app"
    LOG_LEVEL = "INFO"  # 日志输出到文件中的最低等级
    LOG_DIR = "logs/flask-app.log"  # 日志存储目录
    MAX_BYTES = 1024 * 1024 * 200  # 日志文件的最大备份数量
    BACKUP_COUNT = 3


config_env = {
    "development": DevelopmentConfig,
    'production': ProductionConfig,
}
